import axios from 'axios'
import { Message } from 'element-ui'
// import { Loading } from 'element-ui'
const baseURL = 'http://110.40.132.203:8889'
const _fetch = axios.create({
  baseURL
})
// let loadingInstance
_fetch.interceptors.request.use(
  function (config) {
    Message.success('请求中')
    // loadingInstance = Loading.service({ text: '加载中', background: '#c4c4c4' })
    return config
  },
  function (error) {
    window.console.log('error', error)
    return Promise.reject(error)
  }
)

_fetch.interceptors.response.use(
  function (response) {
    console.log('----res----', response)
    // loadingInstance.close()
    if (response.data.code === 200) {
      Message.success('请求成功')
    } else {
      Message.error('请求错误')
    }
    return response
  },
  function (error) {
    // loadingInstance.close()
    // const txt = JSON.parse(JSON.stringify(error))
    Message.error('请求错误')
    return Promise.reject(error)
  }
)

export default _fetch
